<?php
/*
 * @Author: your name
 * @Date: 2020-12-23 12:01:16
 * @LastEditTime: 2020-12-28 10:31:43
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /special/application/common/service/ServerDatabaseBak.php
 */

namespace app\common\service;


use think\Db;

class ServerDatabaseBak
{
    /**
     * @name 添加
     * @param $addData
     * @return int|string
     * @author wx
     * @date 2019/10/29 13:55
     */
    public function add($addData)
    {
        return Db::name('server_database_bak')->insert($addData);
    }

    /**
     * @name 列表
     * @param $params
     * @return array
     * @author wx
     * @date 2019/10/29 13:55
     */
    public function list($params)
    {
        $db = Db::name('server_database_bak');
        if(isset($params['type']) && !empty($params['type'])){
            $db->where('type', $params['type']);
        }
        if(isset($params['ctime']) && !empty($params['ctime']) ){
            $start_time = strtotime($params['ctime']." 00:00:00");
            $end_time = strtotime($params['ctime']." 23:59:59");
            $db->where('ctime','between',[$start_time, $end_time]);
        }

        $list = $db->field('id,type,ctime')->order('id desc')->paginate()->toArray();

        return $list;
    }

    /**
     * @name 查找
     * @param $condition
     * @return array|null|\PDOStatement|string|\think\Model
     * @author wx
     * @date 2019/10/29 13:55
     */
    public function findData($condition)
    {
        return Db::name('server_database_bak')->where($condition)->find();
    }

    /**
     * @name 删除
     * @param $condition
     * @return int
     * @author wx
     * @date 2019/10/29 13:56
     */
    public function del($condition)
    {
        return Db::name('server_database_bak')->where($condition)->delete();
    }
}